<template>
    <div style="width: 100%;height: 100vh;background-color: darkslateblue;overflow: hidden">
        <div style="width: 400px;margin: 150px auto">
            <div style="color: #cccccc;font-size: 30px;text-align: center;padding: 30px">后台登录</div>
            <el-form ref="form" :model="user" size="normal" :rules="rules">
                <el-form-item prop="login">
                    <el-input prefix-icon="el-icon-user-solid" v-model="user.login"></el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input show-password prefix-icon="el-icon-lock" v-model="user.password"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button style="width: 100%" type="primary" @click="login">登 录</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import request from "@/utils/request";

export default {
    name: "BackStageLogin",
    data() {
        return {
            user: {},
            rules: {
                login: [
                    {required: true, message: '请输入用户名', trigger: 'blur'},
                ],
                password: [
                    {required: true, message: '请输入密码', trigger: 'blur'},
                ],
            },
        }
    },
    methods: {
        login() {
            this.$refs['form'].validate((valid) => {
                if (valid) {
                    request.post("/backstage/adminLogin", this.user).then(res => {
                        if (res.message === "成功") {
                            this.$message({
                                type: "success",
                                message: "登陆成功"
                            })
                            localStorage.setItem("admin-user", JSON.stringify(res.user));
                            //后台主页
                            this.$router.push("/backstage/home");
                        } else {
                            this.$message({
                                type: "error",
                                message: res.message
                            })
                        }
                    })
                }
            })
        }
    }
}
</script>

<style scoped>

</style>